//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using System.ComponentModel;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.Design.MatchingRules;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration;
using EntLibContrib.PolicyInjection.Configuration.Design.Properties;

namespace EntLibContrib.PolicyInjection.Configuration.Design.MatchingRules
{
	/// <summary>
	/// And Matching Rule Node
	/// </summary>
	public class AndMatchingRuleNode : MatchingRuleNode, ICompositeMatchingRuleNode
	{
		#region Fields
		private AndMatchingRuleData ruleData;
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="AndMatchingRuleNode"/> class.
		/// </summary>
		public AndMatchingRuleNode()
			: this(new AndMatchingRuleData(Resources.AndMatchingRuleName))
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="AndMatchingRuleNode"/> class.
		/// </summary>
		/// <param name="ruleData">The rule data.</param>
		public AndMatchingRuleNode(AndMatchingRuleData ruleData)
			: base(ruleData)
		{
			this.ruleData = ruleData;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Returns a <see cref="T:Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.MatchingRuleData"/> configuration object from the nodes data.
		/// </summary>
		/// <returns>
		/// A newly created <see cref="T:Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.MatchingRuleData"/> configuration object from the nodes data.
		/// </returns>
		/// <remarks>
		/// Subclasses implement this method to return an instance of a concrete <see cref="T:Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.MatchingRuleData"/> subclass.
		/// </remarks>
		public override MatchingRuleData GetConfigurationData()
		{
			AndMatchingRuleData matchingRuleData = new AndMatchingRuleData(this.Name);
			foreach (MatchingRuleNode node in this.Nodes)
			{
				matchingRuleData.MatchingRules.Add(node.GetConfigurationData());
			}
			return matchingRuleData;
		}
		#endregion

		#region ICompositeMatchingRuleNode Members

		/// <summary>
		/// Gets the child rules.
		/// </summary>
		/// <value>The child rules.</value>
		[Browsable(false)]
		public IEnumerable<MatchingRuleData> ChildRules
		{
			get { return ruleData.MatchingRules; }
		}

		#endregion
	}
}
